package com;

import com.pojo.Customer;
import com.utils.MyBatisUtils;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class CustomerTest {
    @Test
    public void findCustomerByNameAndJobsTest(){
        SqlSession sqlSession= MyBatisUtils.getSession();
        Customer customer = new Customer();
        customer.setUsername("jack");
        customer.setJobs("teacher");

        List<Customer> customer = sqlSession.selectList("findCustomerByNameAndJobs",customer);
        for(Customer cust:customers){
            System.out.println(cust);
        }
        sqlSession.commit();
        sqlSession.close();
    }
}
@Test
public void findCustomerBySetTest() {
    SqlSession sqlSession = MyBatisUtils.getSession();
    Customer customer = new Customer();
    customer.setId(3);
    customer.setPhone("13311111234");
    customer.setUsername("jack");
    int rows = sqlSession.update("updateByPrimaryKeySelectives", customer);
    if (rows > 0){
        System.out.println("更新成功");
    }else{
        System.out.println("更新失败");
    }
    sqlSession.commit();
    sqlSession.close();
}
    @Test
    public void findByArrayTest() {
        SqlSession session = MyBatisUtils.getSession();
        Integer[] roleIds = {2,3};
        List<Customer> customers = session.selectList("com.mapper.Customer.findByArray",roleIds);
        for(Customer customer :customers){
            System.out.println(customer);
        }
        aession.close();
    }
@Test
public void findByListTest() {
    SqlSession sqlSession = MyBatisUtils.getSession();
    List<Integer> ids = new ArrayList<Integer>();
    ids.add(1);
    ids.add(3);
    List<Customer> customers = sqlSession.selectList("findByList", ids);
    for (Customer c : customers) {
        System.out.println(c);
    }
    sqlSession.close();
}